package domain.entities;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * Droga entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "droga", catalog = "bms", uniqueConstraints = {
        @UniqueConstraint(columnNames = "drugNumber"),
        @UniqueConstraint(columnNames = "drugName") })
public class Droga implements java.io.Serializable {

	// Fields

	private Integer id;
	private String drugName;
	private String drugNumber;
	private Set<Safetydocs> safetydocses = new HashSet<Safetydocs>(0);
	private List<Protocolo> protocolos = new ArrayList<Protocolo>();
	private Set<CdaMolecula> cdaMoleculas = new HashSet<CdaMolecula>(0);
    private Set<DrogaImportacion> drogaImportaciones = new HashSet<DrogaImportacion>();

	// Constructors

	/** default constructor */
	public Droga() {
	}

	/** minimal constructor */
	public Droga(String drugName, String drugNumber) {
		this.drugName = drugName;
		this.drugNumber = drugNumber;
	}

	/** full constructor */
	public Droga(String drugName, String drugNumber,
			Set<Safetydocs> safetydocses, List<Protocolo> protocolos,
			Set<CdaMolecula> cdaMoleculas) {
		this.drugName = drugName;
		this.drugNumber = drugNumber;
		this.safetydocses = safetydocses;
		this.protocolos = protocolos;
		this.cdaMoleculas = cdaMoleculas;
	}

    // Property accessors
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "drugName", unique = true, nullable = false)
    public String getDrugName() {
        return this.drugName;
    }

    public void setDrugName(String drugName) {
        this.drugName = drugName;
    }

    @Column(name = "drugNumber", unique = true, nullable = false, length = 10)
    public String getDrugNumber() {
        return this.drugNumber;
    }

    public void setDrugNumber(String drugNumber) {
        this.drugNumber = drugNumber;
    }

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "droga")
	public Set<Safetydocs> getSafetydocses() {
		return this.safetydocses;
	}

	public void setSafetydocses(Set<Safetydocs> safetydocses) {
		this.safetydocses = safetydocses;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "drogas")
    @LazyCollection(LazyCollectionOption.FALSE)
	public List<Protocolo> getProtocolos() {
		return this.protocolos;
	}

	public void setProtocolos(List<Protocolo> protocolos) {
		this.protocolos = protocolos;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "droga")
	public Set<CdaMolecula> getCdaMoleculas() {
		return this.cdaMoleculas;
	}

	public void setCdaMoleculas(Set<CdaMolecula> cdaMoleculas) {
		this.cdaMoleculas = cdaMoleculas;
	}

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "droga")
    @LazyCollection(LazyCollectionOption.FALSE)
    public Set<DrogaImportacion> getDrogaImportaciones() {
        return this.drogaImportaciones;
    }

    public void setDrogaImportaciones(Set<DrogaImportacion> drogaImportaciones) {
        this.drogaImportaciones = drogaImportaciones;
    }

    public void addDrogaImportacion(DrogaImportacion drogaImportacion) {
        this.drogaImportaciones.add(drogaImportacion);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Droga)) return false;

        Droga droga = (Droga) o;

        if (!id.equals(droga.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}